package utils

import (
	"crypto/md5"
	"crypto/rand"
	"crypto/sha256"
	"encoding/hex"
)

// Encryption 密码加密
func Encryption(pwd, salt string) string {
	md5.New()
	hash := sha256.Sum256([]byte(pwd + salt))
	return hex.EncodeToString(hash[:])
}

// SaltGenerate Salt随机数生成
func SaltGenerate() string {
	length := 16 // 生成长度为16的随机字符串

	randomBytes := make([]byte, length)
	if _, err := rand.Read(randomBytes); err != nil {
		panic(err)
	}

	salt := hex.EncodeToString(randomBytes)
	return salt
}
